package wang.raye.springcloud.zuul.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import wang.raye.springcloud.zuul.mapper.ChannelMapper;
import wang.raye.springcloud.zuul.service.ChannelService;

import java.util.concurrent.TimeUnit;

/**
 * Created by Raye on 2018-06-13
 */
@Service
public class ChannelServiceImpl implements ChannelService {

    @Autowired
    private ChannelMapper mapper;
    @Autowired
    private RedisTemplate<String, String> redisTemplate;
    @Override
    public String selectCallurl(String tenantid,String channelid) {
        String cache = redisTemplate.opsForValue().get("CALLURL"+tenantid.toUpperCase()+channelid);
        if(StringUtils.isEmpty(cache)){
            cache = mapper.selectCallurl(tenantid,channelid);
            if(!StringUtils.isEmpty(cache)){
                redisTemplate.opsForValue().set("CALLURL"+tenantid.toUpperCase()+channelid,cache,1, TimeUnit.DAYS);
            }
            return cache;
        }
        return cache;
    }
}
